package pe.com.ztaxi.taxis.util;

import java.io.File;
import java.io.FileInputStream;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import pe.com.ztaxi.taxis.dao.ConductorDAO;
import pe.com.ztaxi.taxis.dao.VehiculoDAO;
import pe.com.ztaxi.taxis.model.Conductor;
import pe.com.ztaxi.taxis.model.Vehiculo;

@Service
public class SnippetImages {
	
	@Resource
	private ConductorDAO c;
	
	@Resource
	private VehiculoDAO v;
	
	@Transactional
	public void grabarFoto(){
		
		
		File file = new File("C:\\Users\\Warlux\\Pictures\\foto.jpg");
        byte[] bFile = new byte[(int) file.length()];
 
        try {
	     FileInputStream fileInputStream = new FileInputStream(file);
	     //convert file into array of bytes
	     fileInputStream.read(bFile);
	     fileInputStream.close();
        } catch (Exception e) {
	     e.printStackTrace();
        }

		Conductor conductor = c.findOne(6);
		conductor.setFoto(bFile);
		c.save(conductor);
		
		File file2 = new File("C:\\Users\\Warlux\\Pictures\\lambo.jpg");
        byte[] bFile2 = new byte[(int) file2.length()];
 
        try {
	     FileInputStream fileInputStream = new FileInputStream(file2);
	     //convert file into array of bytes
	     fileInputStream.read(bFile2);
	     fileInputStream.close();
        } catch (Exception e) {
	     e.printStackTrace();
        }

		Vehiculo veh = v.findOne(2);
		veh.setFoto(bFile2);
		v.save(veh);
	}
	
	@Transactional
	public void grabarFotoVehiculo(){
		
		File file2 = new File("C:\\Users\\Warlux\\Pictures\\lambo.jpg");
        byte[] bFile2 = new byte[(int) file2.length()];
 
        try {
	     FileInputStream fileInputStream = new FileInputStream(file2);
	     //convert file into array of bytes
	     fileInputStream.read(bFile2);
	     fileInputStream.close();
        } catch (Exception e) {
	     e.printStackTrace();
        }

		Vehiculo veh = v.findOne(1);
		veh.setFoto(bFile2);
		v.save(veh);
	}
}

